package com.erb.config.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Component
public class loanLoginInterceptor implements HandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		HttpSession session = request.getSession();
		// 获取session中的对象
		Object user = session.getAttribute("loanuser");
		if (user == null) {
			// 未登录，去往登录页
			response.sendRedirect(request.getContextPath() + "/loan/reglog/tologin");
			return false;
		}
		return true;
	}
}
